package com.android.projetihm.activity.main;

import java.util.LinkedList;
import java.util.List;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.projetihm.R;
import com.android.projetihm.nf.Graphe;

/**
 * Fragment for list view
 * 
 * @author Adrien
 *
 */
public class MainFragment
		extends ListFragment
{
	//+++++++++++//
	// CONSTANTS //
	//+++++++++++//
	
	public static enum MY_TABS
	{
		PHOTOS {
			@Override
			public int getTitleResID() {
				return R.string.title_section1;
			}
		},
		PANORAMAS {
			@Override
			public int getTitleResID() {
				return R.string.title_section2;
			}
		};
		public abstract int getTitleResID();
	}

	public static final String CST_ARG_SECTION_NUMBER = "section_number";
	
	/**
	 * the list of list of photos
	 */
	private List<Graphe> mGrapheList;
	
	/**
	 * the current view
	 */
	private View mView;
	
	
	//+++++++++//
	// METHODS //
	//+++++++++//

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		System.out.println("onCreate");
		super.onCreate(savedInstanceState);
    	if (this.mGrapheList == null)
    	{
			System.out.println("new grapheList");
			this.mGrapheList = new LinkedList<Graphe>();
			this.mGrapheList.add(Graphe.getIdInstance(R.drawable.ic_launcher));
			this.mGrapheList.add(Graphe.getIdInstance(R.drawable.ic_launcher));
			this.mGrapheList.add(Graphe.getIdInstance(R.drawable.ic_launcher));
			this.mGrapheList.add(Graphe.getIdInstance(R.drawable.ic_launcher));
			this.mGrapheList.add(Graphe.getIdInstance(R.drawable.ic_launcher));
			this.mGrapheList.add(Graphe.getIdInstance(R.drawable.ic_launcher));
			this.mGrapheList.add(Graphe.getIdInstance(R.drawable.ic_launcher));
			this.mGrapheList.add(Graphe.getIdInstance(R.drawable.ic_launcher));
        	MainListAdapter listAdapter = new MainListAdapter(
        			this.getActivity(),
        			R.layout.fragment_main_item,
        			this.mGrapheList);
        	
        	this.setListAdapter(listAdapter);
    	}
	}
	
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
		System.out.println("onActivityCreated");
    }

    @Override
    public View onCreateView(
    		LayoutInflater inflater,
    		ViewGroup container,
            Bundle savedInstanceState)
    {
		System.out.println("onCreateView");
		
		if (this.mView == null)
		{
			System.out.println("new view");
	        int tabPosition = this.getArguments().getInt(CST_ARG_SECTION_NUMBER);
	        MY_TABS tab = MY_TABS.values()[tabPosition];
	        
	        switch (tab)
	        {
	        case PHOTOS:
	        	this.mView = this.getViewPhotosList(inflater);
	        	break;
	        case PANORAMAS:
	        	this.mView = this.getViewPhotosList(inflater);
	        	//view = this.getViewPanoramaList();
	        	break;
	        default:
	        	
	        }
		}
        return this.mView;
    }

    /**
     * to get the view for list of list of photos
     * @param inflater which can inflate views
     * @return the view for list of list of photos
     */
    private View getViewPhotosList(LayoutInflater inflater)
    {
    	View view = inflater.inflate(R.layout.fragment_main, null);
        return view;
    }

    /**
     * to get the view for list of panoramas
     * @param inflater which can inflate views
     * @return the view for list of panoramas
     */
//    private View getViewPanoramaList(LayoutInflater inflater)
//    {
//    	// TODO create good panorama list view and return it
//    	TextView textView = new TextView(this.getActivity());
//        textView.setGravity(Gravity.CENTER);
//        textView.setText("Panorama list");
//        return textView;
//    }
    
    
	//++++++++++++++++//
	// STATIC METHODS //
	//++++++++++++++++//
}
